package com.bear.sgg.springboot_06_web.errorPageTest;

import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

/**
 * @ClassNmae MyErrorAttributes
 * @Description 定值错误属性，可以在这里添加自己的错误属性，并
 * @Author bear
 * @Date 2020/3/12 0012 上午 10:12
 */
@Component
public class MyErrorAttributes extends DefaultErrorAttributes {

    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        /*获取原本的错误属性，并添加上自己的错误属性*/
        Map<String, Object> map = super.getErrorAttributes(webRequest, includeStackTrace);
        map.put("company", "bear");

        //从请求域中获取我们的异常信息
        Object ext = webRequest.getAttribute("ext", RequestAttributes.SCOPE_REQUEST);
        //将这些异常信息添加到错误属性中
        map.put("ext", ext);
        return map;
    }


}
